<?php
namespace App\Model;

class MallOrder extends Model
{
    // 表名
    protected $table = 'mall_order';
    
    // 保护属性
    protected $guarded = [];
    
    protected $attributes = [
        'express'       => '',
        'express_code'  => '',
        'express_time'  => '',
        'pay'           => '',
        'pay_time'      => '',
        'ok_time'       => '',
        'status'        => self::STATUS_POST,
        'status_settle' => self::STATUS_SETTLE_NO,
    ];
    
    // 格式
    protected $casts = [
        'goods_image' => 'array',
        'data' => 'array'
    ];

    protected $dateFormat = 'U';
    
    // 状态
    const STATUS_NO      = -1;
    const STATUS_POST    = 0;
    const STATUS_PAY     = 1;
    const STATUS_EXPRESS = 2;
    const STATUS_OK      = 3;
    
    // 结算
    const STATUS_SETTLE_NO = 0;
    const STATUS_SETTLE_OK = 1;
    
    // 用户
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    
    // 商品
    public function goods()
    {
        return $this->belongsTo(MallGoods::class, 'goods_id');
    }
    
    // 商家
    public function shop()
    {
        return $this->belongsTo(MallShop::class, 'shop_id');
    }
}